/*--------------------------------------------------------------------------------------------------
Yatak Operation System Project Copyright 2012-2013
Author : Ilya Churaev
Started : 20 Jan 2013		Updated : 20 Jan 2013
File Name : ext2.h		Purpose : Defines the interface for and structures relating to the ext2 fs.
--------------------------------------------------------------------------------------------------*/
#ifndef EXT2_H
#define EXT2_H

#ifdef __cplusplus
extern "C" {
#endif

#define EXT2_UNKNOWN			0x0
#define EXT2_FILE				0x1
#define EXT2_DIRECTORY			0x2
#define EXT2_CHAR_DEV			0x3
#define EXT2_BLOCK_DEV			0x4
#define EXT2_FIFO				0x5
#define EXT2_SOCKET				0x6
#define EXT2_SYMLINK			0x7
#define EXT2_MAX				0x8

#define EXT2_BAD_INO			0x01	// Bad blocks inode
#define EXT2_ROOT_INO			0x02	// root directory inode
#define EXT2_ACL_IDX_INO		0x03	// ACL index inode (deprecated?)
#define EXT2_ACL_DATA_INO		0x04	// ACL data inode (deprecated?)
#define EXT2_BOOT_LOADER_INO	0x05	// boot loader inode
#define EXT2_UNDEL_DIR_INO		0x06

typedef struct
{
	u32int s_inodes_count;
	u32int s_blocks_count;
	u32int s_r_blocks_count;
	u32int s_free_blocks_count;
	u32int s_free_inodes_count;
	u32int s_first_data_block;
	u32int s_log_block_size;
	u32int s_log_frag_size;
	u32int s_blocks_per_group;
	u32int s_frags_per_group;
	u32int s_inodes_per_group;
	u32int s_mtime;
	u32int s_wtime;
	u16int s_mnt_count;
	u16int s_max_mnt_count;
	u16int s_magic;
	u16int s_state;
	u16int s_errors;
	u16int s_minor_rev_level;
	u32int s_lastcheck;
	u32int s_checkinterval;
	u32int s_creator_os;
	u32int s_rev_level;
	u32int s_def_resuid;
	u32int s_def_resgid;
	//   -- EXT2_DYNAMIC_REV Specific --
	u32int s_first_ino;
	u16int s_inode_size;
	u16int s_block_group_nr;
	u32int s_feature_compat;
	u32int s_feature_incompat;
	u32int s_feature_ro_compat;
	char s_uuid[16];

	char s_volume_name[16];
	char s_last_mounted[64];
	u32int s_algo_bitmap;
	//   -- Performance Hints         --
	u8int s_prealloc_blocks;
	u8int s_prealloc_dir_blocks;
	u16int alignment;
	//   -- Journaling Support        --
	char s_journal_uuid[16];
	u32int s_journal_inum;
	u32int s_journal_dev;
	u32int s_last_orphan;
} superblock_t;

typedef struct
{
	u32int bg_block_bitmap;
	u32int bg_inode_bitmap;
	u32int bg_inode_table;
	u16int bg_free_blocks_count;
	u16int bg_free_inodes_count;
	u16int bg_used_dirs_count;
	u16int bg_pad;
	u8int bg_reserved[12];
} group_desc_t;

typedef struct
{
	u16int i_mode;
	u16int i_uid;
	u32int i_size;
	u32int i_atime;
	u32int i_ctime;
	u32int i_mtime;
	u32int i_dtime;
	u16int i_gid;
	u16int i_links_count;
	u32int i_blocks;
	u32int i_flags;
	u32int i_osd1;
	u32int i_block[15];
	u32int i_generation;
	u32int i_file_acl;
	u32int i_dir_acl;
	u32int i_faddr;
	u8int i_osd2[12];
} inode_t;

typedef struct
{
	u32int inode;
	u16int reclen;
	u8int namelen;
	u8int file_type;
	char name[256];
} dir_t;

#ifdef __cplusplus
}
#endif

#endif
